package com.haohe.wx.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * 
 * @Title MD5密钥生成
 * @Description TODO
 * @author liming.zhao@haohedata.com
 * @date 2015-6-30 
 * @time 上午10:02:35
 */
public enum MD5Generate {

	INSTANCE {
		@Override
		public String get32(String str) {
			MessageDigest messageDigest = null;
			try {
				messageDigest = MessageDigest.getInstance("MD5");
			} catch (NoSuchAlgorithmException e) {
//				UtilLog.ERROR("MD5生成错误！", e);
				return null;
			}
			messageDigest.update(str.getBytes());
			byte[] byteArray = messageDigest.digest();
			StringBuffer stringBuffer = new StringBuffer();
			for (int i = 0; i < byteArray.length; i++) {
				stringBuffer.append(Integer.toHexString((byteArray[i] & 0xFF) | 0x100).substring(1,
						3));
			}
			return stringBuffer.toString();
		}
	};

	public abstract String get32(String str);

}